package com.tianji.jersey.jaxb.resource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.sun.jersey.spi.resource.Singleton;
import com.tianji.jersey.jaxb.bean.FlightType;
import com.tianji.jersey.jaxb.bean.Flights;

@Singleton
@Path(value = "/flights")
public class FlightListResource {

	private Flights myFlights;

	public FlightListResource() {
		myFlights = new Flights();
		FlightType flight123 = new FlightType();
		flight123.setCompany("Czech Airlines");
		flight123.setNumber(123);
		flight123.setFlightId("OK123");
		flight123.setAircraft("B737");
		FlightType flight124 = new FlightType();
		flight124.setCompany("Czech Airlines");
		flight124.setNumber(124);
		flight124.setFlightId("OK124");
		flight124.setAircraft("AB115");
		myFlights.getFlight().add(flight123);
		myFlights.getFlight().add(flight124);
	}

	@GET
	@Produces( { "application/json", "application/xml" })
	public synchronized Flights getFlightList() {
		return myFlights;
	}

	@PUT
	@Consumes( { "application/json", "application/xml" })
	public synchronized void putFlightList(Flights flights) {
		myFlights = flights;
	}
}
